package com.junmeng.lib.acrash

import com.junmeng.libbreakpad.BreakpadUtil
import java.io.File

object ACrash {
    private var aCrashHandler: ACrashHandler? = null
    private var crashStorePath: String? = null
    fun init(
        crashStorePath: String,//dump文件存储目录，需用户自己保证存在
        debug: Boolean = false //是否debug模式，是的话有日志打印
    ) {
        this.crashStorePath = crashStorePath
        aCrashHandler = ACrashHandler.getInstance()
        val logPath = File(crashStorePath, "log")
        if (!logPath.exists()) {
            logPath.mkdirs()
        }
        aCrashHandler?.init(logPath.absolutePath)
        val nativePath = File(crashStorePath, "native")
        if (!nativePath.exists()) {
            nativePath.mkdirs()
        }
        BreakpadUtil.init(nativePath.absolutePath, debug)
    }

    fun uninit() {
        BreakpadUtil.uninit()
    }

    fun testNativeCrash() {
        BreakpadUtil.testNativeCrash()
    }

    fun getCrashStorePath(): String? {
        return crashStorePath
    }
}